package com.seal.commons.core;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 功能描述: <br/>
 *
 * @author yong.huang
 * @date: 2020-08-01 09:21<br/>
 * @since JDK 1.8
 */
public class SecretPropertiesUtils {

    private static final Logger logger = LoggerFactory.getLogger(SecretPropertiesUtils.class);

    private static Properties props;

    static{
        loadProps();
    }

    synchronized static private void loadProps(){
        logger.info("开始加载properties文件内容.......");
        props = new Properties();
        try (InputStream in  = SecretPropertiesUtils.class.getClassLoader().getResourceAsStream("secret.properties");){
            props.load(in);
        } catch (FileNotFoundException e) {
            logger.error("jdbc.properties文件未找到");
        } catch (IOException e) {
            logger.error("出现IOException");
        }
        logger.info("加载properties文件内容完成...........");
    }

    public static String getProperty(String key){
        if(null == props) {
            loadProps();
        }
        return props.getProperty(key);
    }

    public static String getProperty(String key, String defaultValue) {
        if(null == props) {
            loadProps();
        }
        return props.getProperty(key, defaultValue);
    }
}